package com.longge;

import java.util.Arrays;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-05-23 23:32
 */
public class Insertion {

    public void sort(int[] arr) {
        for (int i = 1; i < arr.length; i++) {
            for (int j = i; j > 0; j--) {
                if (arr[j - 1] > arr[j]) {
                    int temp = arr[j];
                    arr[j] = arr[j - 1];
                    arr[j - 1] = temp;
                }else {
                    break;
                }
            }
        }
    }

    public static void main(String[] args) {
        int[] arr = {2, 3, 5, 8, 7, 9, 8, 8, 7, 2, 4, 5};
        new Insertion().sort(arr);
        System.out.println(Arrays.toString(arr));
    }

}
